<template>
    <div id="background">
        <el-container>
            <el-header id="kaoZhengHead">
                <el-row type="flex" style="height:80%;display:flex;align-items: flex-end">
                    <el-col :xs="2" :sm="2" :md="2" :offset="1" class="imgCol">
                        <img v-bind:src="backIcon" class="backSize" @click="back" />
                    </el-col>
                    <el-col :xs="6" :sm="6" :md="6" :offset="6" class="imgCol">
                        <span class="titleSize">考证报名</span>
                    </el-col>
                </el-row>
            </el-header>
            <el-main id="kaoZhengMain" style="backgroundColor:#ffffff">
                <!-- <sticky-slot> -->
                <el-row id="kaoZhengDaoHang">
                    <van-tabs line-height="1px" color="#53cdf5" @change="changeId">
                        <van-tab v-for="(value,key) in gongZhongs" :key="key" :title="value.professionName" :name="value.professionId">
                        </van-tab>
                    </van-tabs>
                </el-row>
                 <!-- </sticky-slot> -->
                <el-row id="kaoZhengContent" > 
                    <el-row>
                    <el-col v-for="(value,key) in zhengShu" :key="key" :span="12" style="padding:0;"  v-infinite-scroll="load" infinite-scroll-disabled="disabled" >
                        <el-card style="margin-left: 10px; margin-right: 10px;margin-top:10px;height:130px" :body-style="{ padding: '0px'}"  @click="goToXiangQing(value.credentialId)">
                            <div  style="position:relative;text-align:center;"  @click="goToXiangQing(value.credentialId)">
                                <el-image v-bind:src="value.picture" style="width:100%;height:85px;border-radius:5px" fit="cover"></el-image>
                                <!-- <div style="position:absolute;left:0;top:18%;right:0;bottom:0">
                                    <span style="font-size:15px;font-weight:600;color:#707070;">
                                        {{value.name}}
                                    </span>                        
                                </div> -->
                            </div>
                            <div  @click="goToXiangQing(value.credentialId)">
                                <el-row  >
                                    <el-col class="imgCol">
                                        <span class="words noHuanHang">
                                            {{value.name}}
                                        </span>
                                    </el-col>
                                </el-row>
                                <el-row type="flex">
                                    <el-col  :xs="2" :sm="2" :md="2" :offset="1">
                                        <i class="el-icon-user-solid" style="font-size:12px;color:#707070"></i>
                                    </el-col>
                                    <el-col  :xs="6" :sm="6" :md="6" >
                                        <span style="font-size:12px" class="words">{{value.number}}</span>
                                     </el-col>
                                    <el-col  :xs="12" :sm="12" :md="12" :offset="3">
                                        <span style="font-size:12px" class="words">查看更多>></span>
                                    </el-col>
                                </el-row>
                                <!-- <el-row>
                                    <el-col style="width:50%;color:#707070;font-size:14px;">
                                        <span style="margin-left:5px;">
                                            <i class="el-icon-s-custom"></i>
                                        </span>
                                        <span>{{value.number}}</span>
                                    </el-col>
                                    <el-col style="width:50%;">
                                        <span style="font-size:14px;color:#707070;" @click="goToXiangQing(value.credentialId)">查看更多</span>
                                    </el-col>
                                </el-row> -->
                            </div>
                        </el-card>
                    </el-col>
                    </el-row>
                </el-row>
            </el-main>
            <div style="height:5px;backgroundColor:#fff"></div>
            <div v-if="loading" class="imgCol">
                <span class="words" style="font-size:14px">加载中...</span>
            </div>
            <div v-if="noMore" class="imgCol">
                <span class="words" style="font-size:14px">没有更多了...</span>
            </div>
        </el-container> 
    </div>    
</template>

<script>
import stickySlot from '../common/stickySlot/stickySlot.vue'
import backIcon from '../../assets/img/mine/back.png'
export default {
    components:{
    stickySlot,
  },
    data(){
        return{
            //绑定加载状态是否显示
            loading: false,
            pageSize:8,
            pageNo:1,
            professionId:1,
            total:0,
            zhengShu:[],
            gongZhongs:[],
            backIcon:backIcon,
            normalHeight:document.documentElement.clientHeight,
        }
    },
    computed: {
      noMore () {
        return this.zhengShu.length>=this.total;
      },
      disabled () {
        return this.loading || this.noMore;
      }
    },
    mounted(){
        var bg = document.getElementById("background");
       // this.normalHeight=document.documentElement.clientHeight;
        console.log("height:"+this.normalHeight);
        bg.style.height = this.normalHeight+"px";
        bg.style.backgroundColor = "#FFFFFF"
        bg.style.margin = "0px";

        var head=document.getElementById("kaoZhengHead");
        var headHeight=this.normalHeight/30 *4 ;
        console.log("headHeight:"+headHeight);
        head.style.height=headHeight+"px";

        // var main=document.getElementById("kaoZhengDaoHang");
        // var mainHeight=this.normalHeight/30 *2.5;
        // main.style.height=mainHeight+"px";

        // var content=document.getElementById("kaoZhengContent");
        // var contentHeight=this.normalHeight/30 *23.5 ;
        // content.style.height=contentHeight+"px";

        this.getZhiYes();
        this.getZhengShu();
    },
    methods:{
        goToXiangQing(credentialId){
            this.$router.push({
                path:'/kaoZheng/zhengShuXiangQing',
                query:{
                    credentialId:credentialId,
                }
            })
        },
        getZhiYes(){
            var URL=this.IP.IP+'/visitor/getProfessionInformation';
            console.log(URL);
            this.$ajax({
                method:'get',
                url:URL,
            }).then(response=>{
                console.log(response.data);
                var code=response.data.code;
                if(code==0){
                    this.gongZhongs=response.data.data.professionInformation;
                    this.professionId=this.gongZhongs[0].professionId;
                    console.log(this.professionId);
                }else{
                    Toast(response.data.msg);
                }
            }).catch(error=>{
                console.log(error);
                //Toast(error);
            })
      },
        getZhengShu(){
            var URL=this.IP.IP+'/credential/general';
            console.log(this.professionId);
            this.$ajax({
                    method:'get',
                    url:URL,
                    params: {
                        professionId:this.professionId,
                        pageNo:this.pageNo,
                        pageSize:this.pageSize,
                    },
                }).then(response =>{
                this.zhengShu=response.data.data.info;
                this.total=response.data.data.total;
                console.log(response);
                }).catch(error => {
                console.log('获取证书失败');
                });
        },
       changeId(name,title){
            this.professionId=name;
            console.log(this.professionId);
            this.getZhengShu();
        },
        back(){
            console.log("back:");
            this.$router.go(-1);
        },
        load () {
            this.loading = true
            setTimeout(() => {
                this.pageNo++;
                this.getZhengShu();
            this.loading = false;

            }, 2000)
        },
    }
}
</script>

<style>
.words{
    color:#909090;
}
.noHuanHang{
    white-space: nowrap;
    overflow: hidden;
}
.imgCol{
    display:flex;
    align-items:center;
    justify-content:center
}
#kaoZhengHead{
  background-color: #53cdf5;
}
#kaoZhengMain{
    padding:0;
    /* background: #FFFFFF; */
}
.backSize{
    height: 26px;
}
.titleSize{
    font-size:1.125em;
    color:#ffffff
}
@media screen and (max-height: 600px){
  .backSize{
      height: 22px;
  }
  .titleSize{
      font-size: 1em;
  }
}
</style>
